package main

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

type Project struct {
	Id      int
	UserId  int
	Name    string
	Path    string
	Address string
	Version int
	Public  int
	Looknum int
}

func (Project) TableName() string {
	return "project"
}

func main() {
	dsn := "root:123456@tcp(39.106.40.170:3306)/sys?charset=utf8mb4&parseTime=True&loc=Local"
	db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		fmt.Println("数据库连接", err.Error())
	}
	//用脚本往数据库中添加10条数据
	for i := 1; i <= 10; i++ {
		db.Create(&Project{
			Id:      i,
			UserId:  i,
			Name:    fmt.Sprintf("张%d", i),
			Path:    fmt.Sprintf("path%d", i),
			Address: fmt.Sprintf("address%d", i),
			Version: i,
			Public:  i,
			Looknum: i,
		})
	}
}
